﻿@page "/AddBooks"
@using Carlife.Inf;
@using ICarlifeService;
@using Models;
@using Microsoft.EntityFrameworkCore;
@using Models.Authority;
@inject IDbContextFactory<CarlifeDbcontext> dbFactory;
@inject IRolesService ibase;
@inject NavigationManager NavigationManager
@inject IJSRuntime jsRuntime
<h3>角色添加</h3>
<PageTitle>角色添加</PageTitle>
<p>
    父级角色ID ：
    <input @bind="@role.Parent_id" type="number"></input>
</p>
<p>
    账户：
    <input @bind="@role.Account" type="text"></input>
</p>
<p>
    名称：
    <input @bind="@role.RoleName" type="text"></input>
</p>
<p>
    角色描述：
    <textarea @bind="@role.Description"></textarea>
</p>
<input type="submit" class="btn btn-primary" @onclick="Save" />

@code {
    //private string Message = string.Empty;
    private static CarlifeDbcontext _context;  
    private Roles role = new Roles();
    protected override Task OnInitializedAsync()
    {
        _context = dbFactory.CreateDbContext();
        return base.OnInitializedAsync();
    }
    private async void Save()
    {
        role.IsData = true;
        int count = ibase.GetRoleAdd(role);
        if (count>0)
        {
            await jsRuntime.InvokeAsync<string>("alert", "保存成功 !");
            NavigationManager.NavigateTo($"BookIndex");
        }
        else
        {
            await jsRuntime.InvokeAsync<string>("alert", "保存失败 !");
        }
    }
}
